﻿using EntityFramework.Entity.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YouTravel.DomainModels;

namespace Repositories.Configuration
{
    public class MenuMap : EntityConfigurationBase<Menu>
    {
        public MenuMap()
        {
            this.Property(p => p.Name).HasMaxLength(20).IsRequired();
            this.Property(p => p.Code).HasMaxLength(8).IsRequired();
            this.Property(p => p.Url).HasMaxLength(500).IsRequired();
            

            this.HasOptional(p => p.ParentMenu).WithMany().HasForeignKey(p=>p.UpMenuId);

            this.HasMany(p => p.Users).WithMany(p => p.Menus).Map(m => {
                m.ToTable("Relation_User_Menu");
                m.MapLeftKey("MenuId");
                m.MapRightKey("UserId");
            });
        }
    }
}
